package com.lili.collection.core;

import com.lili.collection.core.context.Context;
import com.lili.collection.core.executor.Executor;
import com.lili.collection.core.executor.GenericExecutorService;
import com.lili.collection.core.runner.result.RunnerResult;
import lombok.Getter;
import lombok.Setter;

import java.util.Map;

/**
 * 数据流
 *
 * @author lili
 * @date 2023/2/13 18:43
 */
public class ExecutorAdapter {

    ExecutorAdapter() {
    }

    @Getter
    @Setter
    private Context context;

    @Getter
    @Setter
    private Executor executor;

    public ExecutorAdapter(Context context) {
        this.context = context;
    }

    private void ensureExecutor() {
        if (this.executor == null) {
            this.executor = new GenericExecutorService();
        }
    }

    public void execute() {
        ensureExecutor();
        this.executor.execute(this.context);
    }

    public Map<String, RunnerResult> getExecutorResult() {
        return this.executor.getPipeRunnerResult();
    }

    public String getOutputOffset() {
        ensureExecutor();
        this.executor.setContext(this.context);
        return this.executor.getOutputOffset();
    }
}
